
class UserInfo {

  static const String NAME = 'user';
  static const String CREATE = 'CREATE TABLE IF NOT EXISTS $NAME(id INTEGER PRIMARY KEY,nickname TEXT, avatar TEXT,token TEXT, mobile TEXT,tag TEXT)';

  int id;
  String nickname;
  String avatar;
  String token;
  String mobile;
  String tag;

  String getEntcrypyMobile()=> mobile?.replaceRange(3,7, '****')??'';

  UserInfo({
    this.id=0,
    this.nickname='',
    this.avatar='',
    this.token='',
    this.mobile='',
    this.tag='',
  });

  UserInfo.fromJson(Map<String, dynamic> json) {
    id = json['id']??'';
    nickname = json['nickname']??'';
    avatar = json['avatar']??'';
    token = json['token']??'';
    mobile = json['mobile']??'';
    tag = json['tag']??'';
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['nickname'] = this.nickname;
    data['avatar'] = this.avatar;
    data['token'] = this.token;
    data['mobile'] = this.mobile;
    data['tag'] = this.tag;
    return data;
  }

  UserInfo update(UserInfo userInfo,{bool isUpdateToken=true}){
    var info = userInfo??UserInfo();
    id = info.id;
    nickname = info.nickname;
    avatar = info.avatar;
    if(isUpdateToken)
      token = info.token;
    mobile = info.mobile;
    tag = info.tag;
    return this;
  }



}

